package com.zipking.cloud.springbootmybatis.service.impl;

import com.google.common.collect.Maps;
import com.zipking.cloud.springbootmybatis.persistance.entity.MsgLog;
import com.zipking.cloud.springbootmybatis.persistance.mapper.MsgLogMapper;
import com.zipking.cloud.springbootmybatis.service.ThreadTableDataQuery;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
@Slf4j
@Service
public class ThreadTableDataQueryImpl<T> implements ThreadTableDataQuery {
    @Autowired
    private MsgLogMapper msgLogMapper;
    @Autowired
    private ThreadPoolTaskExecutor queryBatchPool;

    @Override
    public Future<List> selectTableDataAsync(Integer page, Integer limit) throws Exception {
        Map<@Nullable String, @Nullable Object> map = Maps.newHashMap();
        map.put("limit", page);
        map.put("num", limit);
        /* return new AsyncResult<>();*/


        Future<List> future = queryBatchPool.submit(() -> {
             log.info("----------");
            List<MsgLog> dataList = msgLogMapper.selectListByWhere(map);
            return dataList;
        });
        return future;
    }
}
